package com.study.sbsummary.utils;

public enum ParamErrorType {
    Success(0, "成功"),
    Fail(1, "失败"),
    MissRequireArgument(101, "缺少必要的请求参数"),
    ArgumentError(102, "请求参数格式错误"),
    DuplicateEntry(601, "数据表唯一键重复错误");

    private final int code;
    private final String message;

    private ParamErrorType(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public ParamErrorType findByCode(int code) {
        switch(code) {
            case 1:
                return Fail;
            case 101:
                return MissRequireArgument;
            case 102:
                return ArgumentError;
            case 601:
                return DuplicateEntry;
            default:
                return Success;
        }
    }
}
